package com.lishe.lishe.lishe.module.mall.http;

import android.content.Context;
import android.util.Log;

import com.lishe.lishe.asynchttp.LSWebHelper;
import com.lishe.lishe.lishe.utils.SharedPreferencesUtils;

import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by zhcase on 2017/9/6.
 */

public class MallHttpHelper {

    private static final String TAG = MallHttpHelper.class.getSimpleName();

    private static final String SIGN_URL = "Home/Index/";


    /**
     * 心意商城首页分类接口 不需要参数
     * @param callBack
     */
    public static void getStoreHomeCategoryList(final LSWebHelper.WebCallBack callBack) {

        String relativeUrl = SIGN_URL + "categoryList";

        HashMap<String, Object> params = new HashMap<String, Object>();

        LSWebHelper.getInstance().getAsyn(relativeUrl,params,new LSWebHelper.WebCallBack(){

            @Override
            public void onSuccess(JSONObject dataJson, String dataString, String message) {

                Log.e(TAG,message);
                //Log.e(TAG,dataJson.toString());
                //Log.e(TAG,dataString);

                if(dataString!=null)
                {
                    if(callBack!=null)
                    {
                        callBack.onSuccess(dataJson,dataString , message);
                        return;
                    }
                }

                if(callBack!=null)
                {
                    callBack.onFailure("参数有误！");
                    return;
                }


            }

            @Override
            public void onFailure(String message) {
                if(callBack!=null)
                {
                    callBack.onFailure(message);
                }
            }
        });
    }

    /**
     * 心意商城首页分类数据接口 需要参数Category id
     * @param callBack
     */
    public static void getStoreHomeCategoryData( final int cate_id , final LSWebHelper.WebCallBack callBack) {

        String relativeUrl = SIGN_URL + "index";
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("cate_id",cate_id);
        LSWebHelper.getInstance().getAsyn(relativeUrl,params,new LSWebHelper.WebCallBack(){

            @Override
            public void onSuccess(JSONObject dataJson, String dataString, String message) {
                Log.e(TAG,message);
                if(dataString!=null) {
                    if(callBack!=null) {
                        callBack.onSuccess(dataJson,dataString , message);
                        return;
                    }
                }
                if(callBack!=null) {
                    callBack.onFailure("参数有误！");
                    return;
                }
            }

            @Override
            public void onFailure(String message) {
                if(callBack!=null) {
                    callBack.onFailure(message);
                }
            }
        });
    }



    /**
     * 鉴权:找回密码 密码设置（最后一步）
     * @param ctx
     * @param params
     * @param callBack
     */
    public static void doSetLoginPassword(final Context ctx,HashMap<String,Object> params,final LSWebHelper.WebCallBack callBack) {
        String relativeUrl = SIGN_URL+"setLoginPassword";
        LSWebHelper.getInstance().postAsyn(relativeUrl,params,callBack);
    }
}
